'use strict';
const moment = require('moment');
module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;
  const trackrecord = app.model.define('trackrecord', {
    id: {
      type: INTEGER,
      autoIncrement: true,
      primaryKey: true,
    },
    info: {
      type: STRING,
    },
    customer_id: {
      type: INTEGER,
    },
    type: {
      type: STRING,
    },
    created_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('created_at')).format(
          'YYYY-MM-DD HH:mm:ss'
        );
      },
    },
    updated_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('updated_at')).format(
          'YYYY-MM-DD HH:mm:ss'
        );
      },
    },
  });

  trackrecord.associate = () => {
    trackrecord.belongsToMany(app.model.Sys.User, {
      through: app.model.Customer.CodeStaff,
      foreignKey: 'code_id',
      otherKey: 'staff_id',
    });
    trackrecord.belongsTo(app.model.Customer.Customer, {
      foreignKey: 'customer_id',
    });
  };
  return trackrecord;
};
